﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Drawing;

namespace AMOOF {
    public class OnOffButton : Panel {

        private bool selected = false;

        public string OnImage { set; get; }
        public string OffImage { set; get; }
        public bool Selected {
            set {
                selected = value;
                UpdateState();
            }
            get {
                return selected;
            }
        }
        public string Text { set; get; }
        public Font Font { set; get; }

        public OnOffButton() {
            InitializeComponents();
        }

        private void UpdateState() {
            this.BackgroundImage = (Bitmap)Properties.Resources.ResourceManager.GetObject(Selected ? OnImage : OffImage);
        }

        private void InitializeComponents() {
            Width = 24;
            Height = 24;
            this.Font = new Font("Arial", 11, FontStyle.Regular);
            this.BackgroundImageLayout = ImageLayout.Stretch;

            OnImage = "btn_round_blue_on";
            OffImage = "btn_round_blue_off";
            this.MouseClick += new MouseEventHandler(OnOffButton_MouseClick);

        }

        protected override void OnPaint(PaintEventArgs e) {
            base.OnPaint(e);
            //Text = "Optimize Models";
            //NavFont = new Font("Arial", 13, FontStyle.Bold);
            SizeF size = new SizeF();
            size = e.Graphics.MeasureString(Text, Font);
            float x = (this.Width - size.Width) / 2;
            float y = ((this.Height - size.Height) / 2);
            Brush b = this.Enabled ? Brushes.White : Brushes.Gray;

            e.Graphics.DrawString(Text, Font, b, x, y, StringFormat.GenericDefault);
        }

        private bool MouseIn(Control c, MouseEventArgs e) {
            if (e.X > 0 &&
                e.X < c.Width &&
                e.Y > 0 &&
                e.Y < c.Height) {
                return true;
            }

            return false;
        }

        private void OnOffButton_MouseClick(object sender, MouseEventArgs e) {
            Selected = Selected == true ? false : true;
        }


    
    }
}
